package com.sunny.t2;

import java.util.Scanner;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {

    private static final int MAXN = 1005;

    private static int[][] direct = {{0,1},{0,-1},{1,0},{-1,0}};

    static int[][] data = new int[MAXN][MAXN];
    static int m;

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        m = scanner.nextInt();
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                data[i][j] = scanner.nextInt();
            }
        }

        int res = 0;

        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                if(1 == data[i][j]){
                    res++;
                    bfs(new Point(i,j));
                }
            }
        }
        System.out.println(res);

//        for(int i=0;i<m;i++){
//            for(int j=0;j<m;j++){
//                System.out.print(data[i][j] + " ");
//            }
//            System.out.println();
//        }



    }

    public static void bfs(Point s){
        LinkedBlockingQueue<Point> queue = new LinkedBlockingQueue<>();
        queue.offer(s);
        while (!queue.isEmpty()){
            Point tmp = queue.poll();
            data[tmp.i][tmp.j] = 0;
            for(int k=0;k<direct.length;k++){
                Point next = new Point(tmp.i+direct[k][0], tmp.j+direct[k][1]);
                if(!judge(next))
                    continue;
                if(1 == data[next.i][next.j]){
                    queue.offer(next);
                }
            }
        }
    }

    public static boolean judge(Point p){
        if(p.i < 0 || p.i >= m || p.j < 0 || p.j >= m){
            return false;
        }
        return true;
    }

}


class Point{
    int i,j;

    public Point(int i, int j) {
        this.i = i;
        this.j = j;
    }
}